package com.shameit.goodqrinfomanager.ui.activity.query;

import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.os.Bundle;

import com.chad.library.BR;
import com.shameit.goodqrinfomanager.AppViewModelFactory;
import com.shameit.goodqrinfomanager.BaseMVVMActivity;
import com.shameit.goodqrinfomanager.R;
import com.shameit.goodqrinfomanager.adapter.QueryAdapter;
import com.shameit.goodqrinfomanager.bean.enity.QueryListBean;
import com.shameit.goodqrinfomanager.databinding.ActivityInteQueryBinding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class InteQueryActivity extends BaseMVVMActivity<ActivityInteQueryBinding,InteQueryViewModel> {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setToolBarBack(binding.toolbar);
    }

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_inte_query;
    }

    @Override
    public int initVariableId() {
        return BR.viewmodel;
    }

    @Override
    public InteQueryViewModel initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, factory).get(InteQueryViewModel.class);
    }

    @Override
    protected String setTitle() {
        return "综合查询";
    }

    @Override
    protected void initView() {
        binding.queryList.setLayoutManager(new LinearLayoutManager(this));
        binding.queryList.setAdapter(viewModel.queryAdapter = new QueryAdapter(R.layout.item_query_list));
    }

    private final static String[] types = {"登录", "出库", "入库"};


    @Override
    protected void loadData() {
        ArrayList list = new ArrayList();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yy/MM/dd HH:mm:ss");
        for (int i = 0; i < 5; i++) {
            QueryListBean bean = new QueryListBean();
            bean.setType(types[i % 3]);
            bean.setTime(simpleDateFormat.format(new Date()));
            list.add(bean);
        }
        viewModel.queryAdapter.setNewInstance(list);
    }
}